﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ACH
{
    public partial class ChooseAccomodation : Form
    {
        DataTable _source;
        string _selectedValue;

        List<RadioButton> rooms;
        public ChooseAccomodation(DataTable source, string selectedValue)
        {
            InitializeComponent();
            _source = source;
            _selectedValue = selectedValue;
            FillRadioButtons();
        }

        private void FillRadioButtons()
        {
            int i = 0;
            rooms = new List<RadioButton>();
            foreach (DataRow item in _source.Rows)
            {
                RadioButton b = new RadioButton();
                b.Name = item["Room"].ToString();
                RoomOccupancy ro = new RoomOccupancy(item["ID"].ToString(), (int)item["Total"], (int)item["Available"], item["Room"].ToString());
                b.Tag = ro;
                b.Text = ro.RoomName + "   -   " + ro.AvailablePlaces.ToString() + "/" + ro.TotalPlaces.ToString();
                b.Location = new Point(i++ * 2, 15);
                b.AutoSize = true;
                if (ro.AvailablePlaces == 0)
                    b.Enabled = false;
                if (_selectedValue == ro.LodgingRoomID)
                {
                    b.Checked = true;
                    b.Enabled = true;
                }

                b.CheckedChanged += new EventHandler(b_CheckedChanged);
                rooms.Add(b);
                flowLayoutPanel1.Controls.Add(b);
            }
        }

        void b_CheckedChanged(object sender, EventArgs e)
        {
            //RadioButton r = sender as RadioButton;
            //if (r.Checked)
            //    AddNewLink(r);
            //else
            //    RemoveLink(r);
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }

        private void btnChoose_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
    }
}
